<?php 
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
	session_start(); 
}

		if(isset($_SESSION['lang']))
		$lang=$_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
	include "../../value/value_en.php";
} else if($lang == "VN") {
	include "../../value/value_vn.php";
}
else {
	include "../../value/value_kr.php";
}
include '../../operations/connection.php';
include '../../generallibraries/funcs.php';

if(isset($_REQUEST['hanhdong'])){
	if($_REQUEST['hanhdong']=='add'){
		$number_time_work=$_REQUEST['numtime'];
		$number_max_holiday=$_REQUEST['numholiday'];
		$allowance_holiday=generalFunctions::numberformat_to_basicString($_REQUEST['aholiday']);
		$allowance_lunch=generalFunctions::numberformat_to_basicString($_REQUEST['alunch']);
		$allowance_car=generalFunctions::numberformat_to_basicString($_REQUEST['acar']);
		$allowance_hard=generalFunctions::numberformat_to_basicString($_REQUEST['ahard']);
		$allowance_overtime=generalFunctions::numberformat_to_basicString($_REQUEST['aovertime']);
		$is_status=$_REQUEST['astatus'];
		$user_create=$_REQUEST['ausercreate'];
		if($is_status==1){
			$q="update sa_general_allowance set sa_general_allowance.is_status=0";
			mysql_query($q);
		}
		$query="insert into sa_general_allowance (number_time_work,number_max_holiday,allowance_holiday,allowance_lunch,allowance_car,allowance_hard,allowance_overtime,is_status,user_create,createDate) 
		values(".$number_time_work.",".$number_max_holiday.",".$allowance_holiday.",".$allowance_lunch.",".$allowance_car.",".$allowance_hard.",".$allowance_overtime.",".$is_status.",'".$user_create."',now())";
		mysql_query($query);
	}else if($_REQUEST['hanhdong']=='del'){
		$iddel=$_REQUEST['idgen'];
		$query="DELETE from sa_general_allowance where sa_general_allowance.is_status=0 and sa_general_allowance.id=".$iddel;
		$kq=mysql_query($query);
	}else if($_REQUEST['hanhdong']=='update'){
		$iddel=$_REQUEST['idgen'];
		$number_time_work=$_REQUEST['numtime'];
		$number_max_holiday=$_REQUEST['numholiday'];
		$allowance_holiday= generalFunctions::numberformat_to_basicString($_REQUEST['aholiday']);
		$allowance_lunch=generalFunctions::numberformat_to_basicString($_REQUEST['alunch']);
		$allowance_car=generalFunctions::numberformat_to_basicString($_REQUEST['acar']);
		$allowance_hard=generalFunctions::numberformat_to_basicString($_REQUEST['ahard']);
		$allowance_overtime=generalFunctions::numberformat_to_basicString($_REQUEST['aovertime']);
		$is_status=$_REQUEST['astatus'];
		
		if($is_status==1){
			$q="update sa_general_allowance set sa_general_allowance.is_status=0";
			mysql_query($q);
		}
		
		$sql="UPDATE sa_general_allowance set sa_general_allowance.allowance_car=".$allowance_car."  , 
		sa_general_allowance.allowance_hard=".$allowance_hard." , 
		sa_general_allowance.allowance_holiday=".$allowance_holiday." , 
		sa_general_allowance.allowance_lunch=".$allowance_lunch." , 
		sa_general_allowance.allowance_overtime=".$allowance_overtime." ,
		sa_general_allowance.is_status=".$is_status." ,
		sa_general_allowance.number_max_holiday=".$number_max_holiday." ,
		sa_general_allowance.number_time_work=".$number_time_work." ,
		sa_general_allowance.time_last_update=now() ,
		sa_general_allowance.user_last_update='".$_SESSION['IDEmployee']."' where sa_general_allowance.id=".$iddel;
		mysql_query($sql);
	}
}

$query="select sa_general_allowance.id, sa_general_allowance.allowance_car,sa_general_allowance.allowance_hard,sa_general_allowance.allowance_holiday,sa_general_allowance.allowance_lunch,sa_general_allowance.allowance_overtime,sa_general_allowance.is_status,sa_general_allowance.number_max_holiday,sa_general_allowance.number_time_work from sa_general_allowance order by sa_general_allowance.is_status desc";
$m_query=mysql_query($query);
?>
				<table class="cssTable" border="1" >
					<thead>
						<tr>
							<th scope="col" style="width:10px"></th>
							<th scope="col" style="height:45px;"><?php echo $l_number_time_work;?></th>
							<th scope="col"><?php echo $l_number_max_holiday;?></th>
							<th scope="col"><?php echo $l_allowance_holiday;?></th>
							<th scope="col"><?php echo $l_allowance_lunch;?></th>
							<th scope="col"><?php echo $l_allowance_car;?></th>
							<th scope="col"><?php echo $l_allowance_hard;?></th>
							<th scope="col"><?php echo $l_allowance_overtime;?></th>
							<th scope="col"><?php echo $l_Activestatus;?></th>
						</tr>
					</thead>
					<tbody>
						<?php 
							if(mysql_num_rows($m_query)>0){
								$i=0;
								while($row=mysql_fetch_array($m_query)){
								
									if($row[is_status]==1){
										?>
									<tr style="color:green;">
										<?php 
									}else{
									?>
									<tr>
									<?php }?>
									<td style="width: 10px"><div style="text-align:center"><input onclick="checkonly(this.id,document.nsa_f_general_allowance.list);" type="checkbox" name="list" id="<?php echo 'checkcus'.$i?>" value="<?=$row[id]?>"/></div></td>
									<td ><?php echo $row[number_time_work];?></td>
									<td><?php echo $row[number_max_holiday];?></td>
									<td ><?php echo number_format($row[allowance_holiday]);?></td>
									<td ><?php echo number_format($row[allowance_lunch]);?></td>
									<td ><?php echo number_format($row[allowance_car]);?></td>
									<td><?php echo number_format($row[allowance_hard]);?></td>
									<td ><?php echo number_format($row[allowance_overtime]);?></td>
									<td >
										<?php 
											if($row[is_status]==1){
												echo $l_active;
											}else{
												echo $l_status_saved;
											}
										?>
									</td>
									</tr>
								<?php 
									$i++;
								}
							}
						?>
					</tbody>
				</table>
				<?php mysql_close($connection);?>